/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.google.code.smon.pers;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author xero
 */
@Entity
@Table(name = "server")
@NamedQueries({
    @NamedQuery(name = "Server.findAll", query = "SELECT s FROM Server s")})
public class Server implements Serializable {

    @Basic(optional = false)
    @Lob
    @Column(name = "ip", nullable = false)
    private String ip;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "server")
    private ServerStatus serverStatus;
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "port")
    private int port;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @OneToMany(mappedBy = "serverId")
    private Collection<ServerActions> serverActionsCollection;
    @JoinColumn(name = "type", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private ServerType type;

    public Server() {
    }

    public Server(Integer id) {
        this.id = id;
    }

    public Server(Integer id, String ip, int port, String name) {
        this.id = id;
        this.ip = ip;
        this.port = port;
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Collection<ServerActions> getServerActionsCollection() {
        return serverActionsCollection;
    }

    public void setServerActionsCollection(Collection<ServerActions> serverActionsCollection) {
        this.serverActionsCollection = serverActionsCollection;
    }

    public ServerType getType() {
        return type;
    }

    public void setType(ServerType type) {
        this.type = type;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Server)) {
            return false;
        }
        Server other = (Server) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getName() + "[ id=" + id + ", addr=" + getIp() + ":" + getPort() + ", status=[" + getServerStatus() + "] ]";
    }

    public ServerStatus getServerStatus() {
        return serverStatus;
    }

    public void setServerStatus(ServerStatus serverStatus) {
        this.serverStatus = serverStatus;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }
}
